#include <DotSort/Game.hpp>

#include <SFML/System/Clock.hpp>

#include <SFML/Graphics/RenderWindow.hpp>

#include <SFML/Window/Event.hpp>
#include <SFML/Window/Keyboard.hpp>


Game::Game() :
	window(new sf::RenderWindow(sf::VideoMode::getDesktopMode(), this->name, sf::Style::Fullscreen))
{
	this->window->setFramerateLimit(30);
}

Game::~Game()
{
	this->window->close();
	delete this->window;
}

void Game::run()
{
	// To minimize gap between creation and run()
	// Is it important?
	this->clock.restart();

	while(!this->quit)
	{
		this->update();
		this->processEvents();
		this->draw();
	}
}

void Game::draw()
{
	this->window->clear(sf::Color::White);
	this->window->display();
}

void Game::update()
{
}

void Game::processEvents()
{
	sf::Event event;
	while (this->window->pollEvent(event))
	{
		if(event.type == sf::Event::Closed)
		{
			this->quit = true;
		}
		else if(event.type == sf::Event::KeyPressed)
		{
			if(event.key.code == sf::Keyboard::Escape)
			{
				this->quit = true;
			}
		}
	}
}
